#encoding=utf-8
'''
Created on 2012-12-18

@author: Administrator
'''
from base.common import retError, getFilePrefix, retSuccess
from config.settings import PROJECT_PATH #@UnresolvedImport
import datetime
import random

webPath="/web/upload/"
uploadPath=PROJECT_PATH+"/yqy"+webPath

def do(request):
    if(len(request.FILES)<0):
        return retError("请选择要上传的文件")
    file=request.FILES.get("file") #@ReservedAssignment
    
    prefix=getFilePrefix(file.name)
    
    fileName = datetime.datetime.now().strftime("%Y%m%d%f")+str(random.randint(1,100))
    filePath=uploadPath+fileName+prefix
    uploadFile=open(filePath,"wb")
    uploadFile.write(file.read())
    uploadFile.close()
    
    return retSuccess(webPath+fileName+prefix);
        

    